package view.concret 
{
	/**
	 * @author Alejandro
	 */
	
	import flash.display.Shape;
	import flash.events.Event;
	import view.elements.ConcretApplication;
	
	public class MoveBall extends ConcretApplication{
		
		private var xMin:Number;
		private var yMin:Number;
		private var xMax:Number;
		private var yMax:Number;
		private var xCurrent:Number;
		private var yCurrent:Number;
		private var xMove:Number;
		private var yMove:Number;
		private var radius:Number;
		
		public function MoveBall(){
			super(this);
			init();
			draw();
		}
		
		private function draw():void{
			this.graphics.clear();
			this.graphics.beginFill(0xFF0000,0.75);
			this.graphics.drawCircle(xCurrent,yCurrent,radius);
			this.graphics.endFill();
		}
		
		private function init():void {			
			this.radius   = 50;
			this.xMin     = this.radius;
			this.yMin     = this.radius;
			this.xMax     = 800 - this.radius;
			this.yMax     = 600 - this.radius;
			this.xCurrent = 100;
			this.yCurrent = 100;
			this.xMove    = 1;
			this.yMove    = 1;
		}	
	
		public override function playApplication():void{
			this.addEventListener(Event.ENTER_FRAME, move);
		}
		
		public override function stopApplication():void{			
			this.removeEventListener(Event.ENTER_FRAME, move);
		}
		
		public function xDes():Number{
			return this.xMove * 10;
		}
		
		public function yDes():Number{
			return this.yMove * 10;
		}
		
		public function move(event:Event):void{
			this.xCurrent += xDes();
			if(xCurrent > xMax){
				xMove = -xMove;
				xCurrent = xMax - (xCurrent - xMax);
			}
			if(xCurrent < xMin){
				xMove = -xMove;
				xCurrent = xMin + (xMin - xCurrent);
			}
			
			this.yCurrent += yDes();
			if(yCurrent > yMax){
				yMove = -yMove;
				yCurrent = yMax - (yCurrent - yMax);
			}
			if(yCurrent < yMin){
				yMove = -yMove;
				yCurrent = yMin + (yMin - yCurrent);
			}			
			draw();
		}
	}

}